package com.winteam.Test;

import com.winteam.Bean.RoomInfo;
import com.winteam.Controler.RoomSelect;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.List;
import java.util.Vector;

public class TestTable extends JFrame {

    public TestTable(){
        setSize(600,800);
        setLocationRelativeTo(null);
        //数据模型
        Vector<String> roomInfoHead = new Vector<>();
        roomInfoHead.add("房间号");
        roomInfoHead.add("房间类型");
        roomInfoHead.add("房间状态");
        roomInfoHead.add("钟点价格/小时");
        roomInfoHead.add("床位数量");
        List<RoomInfo> roomInfoBody= RoomSelect.getRoomInfo();
        Vector<Vector<Object>> roomInfodate = new Vector<>();
        for (RoomInfo roomInfo : roomInfoBody) {
            Vector<Object> v = new Vector<>();
            v.add(roomInfo.getR_rommber());
            v.add(roomInfo.getR_type());
            v.add(roomInfo.getR_state());
            v.add(roomInfo.getR_price());
            v.add(roomInfo.getR_bednumber());
            roomInfodate.add(v);
        }
        DefaultTableModel roomInfoDT=new DefaultTableModel(roomInfodate,roomInfoHead);

        JTable table = new JTable(roomInfoDT);

        table.setBounds(0, 100,400,200);

        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.getTableHeader().setReorderingAllowed(false);
        table.setSelectionBackground(Color.red);

        add(table);
        setVisible(true);

    }
    public static void main(String[] args) {

        new TestTable();




        //表格

    }
}
